package it.antonio.ilpizze.servlet.render;


public class JsonUtil {
	
	
	
	public static String escapeToJson(char charToEscape) {
		if (charToEscape == '"') {
			return "\\\"";
		}
		if (charToEscape == '/') {
			return "\\/";
		}
		if (charToEscape == '\n') {
			return "\\n";
		}
		if (charToEscape == '\r') {
			return "\\r";
		}
		return String.valueOf(charToEscape);
	}

	public static String escapeToJson(String str) {
		StringBuffer b = new StringBuffer();
		
		char[] charArray = str.toCharArray();
		for(char c: charArray){
			b.append(escapeToJson(c));
		}
		
		return b.toString();
	}

}
	
	
	

